//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.rightin.serialportapi;

import android.util.Log;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class SerialPortOpt extends SerialPortJNI {
    private static final String TAG = "SerialPort";
    private FileInputStream mFileInputStream;
    private FileOutputStream mFileOutputStream;

    public SerialPortOpt() {
    }

    public FileDescriptor openDev(String path) {
        super.mFd = super.openDev(path);
        if (super.mFd == null) {
            Log.e("SerialPort", "native open returns null");
            return null;
        } else {
            this.mFileInputStream = new FileInputStream(super.mFd);
            this.mFileOutputStream = new FileOutputStream(super.mFd);
            return super.mFd;
        }
    }

    public InputStream getInputStream() {
        return this.mFileInputStream;
    }

    public OutputStream getOutputStream() {
        return this.mFileOutputStream;
    }

    public int setSpeed(FileDescriptor optFd, int speed) {
        return super.setSpeed(optFd, speed);
    }

    public int setParity(FileDescriptor optFd, int databits, int stopbits, int parity) {
        return super.setParity(optFd, databits, stopbits, parity);
    }

    public int closeDev(FileDescriptor optFd) {
        int retStatus = super.closeDev(optFd);
        super.mFd = null;
        return retStatus;
    }

    public int readBytes(byte[] buffer, int offset, int count) throws IOException {
        return this.mFileInputStream.read(buffer, offset, count);
    }

    public int readBytes(FileDescriptor fd, byte[] buffer, int length) {
        return super.readBytes(fd, buffer, length);
    }

    public boolean writeBytes(FileDescriptor fd, byte[] buffer, int length) {
        return super.writeBytes(fd, buffer, length);
    }

    public int readBytes(FileDescriptor fd, byte[] buffer) {
        return super.readBytes(fd, buffer, buffer.length);
    }

    public boolean writeBytes(FileDescriptor fd, byte[] buffer) {
        return super.writeBytes(fd, buffer, buffer.length);
    }

    public int readBytes(byte[] buffer) {
        return super.readBytes(this.mFd, buffer, buffer.length);
    }

    public boolean writeBytes(byte[] buffer) {
        return super.writeBytes(this.mFd, buffer, buffer.length);
    }
}
